package com.research.project.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.research.project.dto.ProjectDocDto;
import com.research.project.vo.ProjectDocVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.research.common.annotation.Log;
import com.research.common.core.controller.BaseController;
import com.research.common.core.domain.AjaxResult;
import com.research.common.enums.BusinessType;
import com.research.project.domain.ProjectDoc;
import com.research.project.service.IProjectDocService;
import com.research.common.utils.poi.ExcelUtil;
import com.research.common.core.page.TableDataInfo;

/**
 * 项目文档Controller
 * 
 * @author ghn
 * @date 2025-09-07
 */
@RestController
@RequestMapping("/project/doc")
public class ProjectDocController extends BaseController
{
    @Autowired
    private IProjectDocService projectDocService;

    /**
     * 查询项目文档列表
     */
    @PreAuthorize("@ss.hasPermi('project:doc:list')")
    @GetMapping("/list")
    public TableDataInfo list(ProjectDocDto projectDocDto)
    {
        startPage();
        List<ProjectDocVo> list = projectDocService.selectProjectDocList(projectDocDto);
        return getDataTable(list);
    }

    /**
     * 导出项目文档列表
     */
//    @PreAuthorize("@ss.hasPermi('project:doc:export')")
//    @Log(title = "项目文档", businessType = BusinessType.EXPORT)
//    @PostMapping("/export")
//    public void export(HttpServletResponse response, ProjectDoc projectDoc)
//    {
//        List<ProjectDoc> list = projectDocService.selectProjectDocList(projectDoc);
//        ExcelUtil<ProjectDoc> util = new ExcelUtil<ProjectDoc>(ProjectDoc.class);
//        util.exportExcel(response, list, "项目文档数据");
//    }

    /**
     * 获取项目文档详细信息
     */
    @PreAuthorize("@ss.hasPermi('project:doc:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(projectDocService.selectProjectDocById(id));
    }

    /**
     * 新增项目文档
     */
    @PreAuthorize("@ss.hasPermi('project:doc:add')")
    @Log(title = "项目文档", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProjectDocDto projectDocDto)
    {
        return toAjax(projectDocService.insertProjectDoc(projectDocDto));
    }

    /**
     * 修改项目文档
     */
    @PreAuthorize("@ss.hasPermi('project:doc:edit')")
    @Log(title = "项目文档", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProjectDoc projectDoc)
    {
        return toAjax(projectDocService.updateProjectDoc(projectDoc));
    }

    /**
     * 删除项目文档
     */
    @PreAuthorize("@ss.hasPermi('project:doc:remove')")
    @Log(title = "项目文档", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(projectDocService.deleteProjectDocByIds(ids));
    }
}
